import request from '@/utils/request';

const bath = "http://localhost:9876/rest"

function req(url, method, param, head, body) {
  let data = {}
  if (param) {
    let str = JSON.stringify(param).replace("{", "").replace("}", "").replace(/\",\"/g, "&").replace(/,\"/g, "&").replace(/:/g, "=").replace(/\":\"/g, "=").replace(/\"/g, "");
    url = bath + url + "?" + str;
  } else {
    url = bath + url;
  }
  if (!method) {
    method = 'GET';
  }
  if (!head) {
    head = {token: localStorage.getItem("token")};
  }
  if (!head['Content-Type']) {
    head['Content-Type'] = "application/json;charset=UTF-8";
  }
  if (body) {
    data.body = JSON.stringify(body);
  }
  data.method = method;
  data.headers = head;

  return request(url, data);
}

export default req;
